package com.angis.fx.activity.service;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;

import com.angis.fx.data.DutyInfo;
import com.angis.fx.handler.login.UpdateHandler;

public class UploadDutyInfoService extends Service {
	
	private Intent mIntent;

	@Override
	public void onCreate() {
		super.onCreate();
//		Intent lIntent = 
		
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		mIntent = new Intent("upLoadResult");
		try {
			int flag = UpdateHandler.uploadDutyInfo(this, (DutyInfo)intent.getExtras().get("dutyinfo"));
			Bundle lBundle = new Bundle();
			if(flag == -1) {
				lBundle.putInt("results", -1);
				Toast.makeText(this, "服务器连接错误!", Toast.LENGTH_SHORT).show();
			}else if(flag == 0){
				lBundle.putInt("results", 0);
				Toast.makeText(this, "执勤信息上传错误!", Toast.LENGTH_SHORT).show();
			}else if(flag == 1){
				lBundle.putInt("results", 1);
				Toast.makeText(this, "执勤信息上传完成!", Toast.LENGTH_SHORT).show();
			}
			mIntent.putExtras(lBundle);
			this.sendBroadcast(mIntent);
		} catch (Exception e) {} finally {this.stopSelf();}
	}

}
